package com.lx.controller;

import com.lx.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class LoginController {

    @RequestMapping("goLogin")
    public String goLogin() {
        return "login";
    }

    @RequestMapping("goMain")
    public String goMain() {
        return "main";
    }

    @RequestMapping("login")
    public String login(HttpSession session, User user, Model model) {
        System.out.println(user.getUsername() + "====" + user.getPassword());
        //用户数据存到session中
        session.setAttribute("userInfo", user);
        model.addAttribute("username",user.getUsername());
        return "main";
    }

    @RequestMapping("goOut")
    public String goOut(HttpSession session) {
        //移除session信息
        session.removeAttribute("userInfo");
        //重定向到登录页面
        return "redirect:/user/goLogin";
    }
}
